package com.alan.mr;

import lombok.Data;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * 封装类
 * Created by Alan on 2017/10/2.
 */
@Data
public class KeyPair implements WritableComparable<KeyPair>{

    private int year;
    private int hot;

    @Override
    public void readFields(DataInput in) throws IOException {
        this.year = in.readInt();
        this.hot = in.readInt();
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(year);
        out.writeInt(hot);
    }

    @Override
    public int compareTo(KeyPair o) {
        int res =Integer.compare(year,o.getYear());
        if(res != 0){
            return res;
        }
        return Integer.compare(hot,o.getHot());
    }

    @Override
    public String toString() {
        return year + "\t" + hot;
    }

    @Override
    public int hashCode() {
        return new Integer(year+hot).hashCode();
    }
}
